﻿namespace plug_uconv
{
    enum prefix : sbyte
    {
        Pico = -12,
        Nano = -9,
        Mikro = -6,
        Mili = -3,
        Centi = -2,
        Deci = -1,
        Deka = 1,
        Hekto = 2,
        Kilo = 3,
        Mega = 6,
        Giga = 9,
        Terra = 12,
        Peta = 15,
        Exa = 18,
        Nullprefix = 0
    }

    class PrefixParser
    {
        public PrefixParser() { }
        public static string[] splitprefix(string unit)
        {
            string[] returnval = new string[2];
            returnval[0] = "Nullprefix";
            returnval[1] = unit;
            string[] prefixes = new string[]
            {
                "pico",
                "nano",
                "mikro",
                "mili",
                "centi",
                "deci",
                "deka",
                "hekto",
                "kilo",
                "mega",
                "giga",
                "tera",
                "peta",
                "exa",
            };
            int cutstart, cutlength;
            foreach (string prefix in prefixes)
            {
                if ((unit.Length > 1) && (unit.StartsWith(prefix)))
                {
                    returnval[0] = prefix;
                    cutstart = unit.IndexOf(prefix, 0);
                    cutlength = prefix.Length;
                    returnval[1] = unit.Remove(cutstart, cutlength);
                    return returnval;
                }
            }
            return returnval;
        }
        public static prefix parseprefix(string iprefix)
        {
            switch (iprefix)
            {
                case "pico":
                    return prefix.Pico;
                case "nano":
                    return prefix.Nano;
                case "mikro":
                    return prefix.Mikro;
                case "mili":
                    return prefix.Mili;
                case "centi":
                    return prefix.Centi;
                case "deci":
                    return prefix.Deci;
                case "deka":
                    return prefix.Deka;
                case "hekto":
                    return prefix.Hekto;
                case "kilo":
                    return prefix.Kilo;
                case "mega":
                    return prefix.Mega;
                case "giga":
                    return prefix.Giga;
                case "tera":
                    return prefix.Terra;
                case "peta":
                    return prefix.Peta;
                case "exa":
                    return prefix.Exa;
                default:
                    return prefix.Nullprefix;
            }
        }
    }

    enum convAction : byte
    {
        none,
        add,
        multiply,
        divide,
        subtract
    }

    class Unit
    {
        public string Name;
        public string sName;
        public double Ratio;
        public string Category;
        public convAction Action;
        public Unit(string N, string sN, string cat, double ratio, convAction A)
        {
            this.Name = N;
            this.sName = sN;
            this.Category = cat;
            this.Ratio = ratio;
            this.Action = A;
        }
        public Unit()
        {
            this.Name = null;
            this.sName = null;
            this.Category = null;
            this.Ratio = double.NaN;
            this.Action = convAction.none;
        }
    }
}